// 
// Decompiled by Procyon v0.5.36
// 

package com.orange.boot.environment.controller;

import org.springframework.web.bind.annotation.PostMapping;
import com.orange.boot.environment.entity.EnvironmentData;
import java.util.Collection;
import java.util.Arrays;
import java.util.List;
import com.orange.boot.environment.util.MapToEnvironmentDataConverter;
import java.util.HashMap;
import java.util.ArrayList;
import com.orange.boot.utils.R;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
import com.orange.boot.environment.service.EnvironmentDataService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/orange_service/environment"})
@Api(
        tags = {"订阅设备数据回调接口"}
)
public class EnvironmentCallbackController {
    EnvironmentDataService service;

    @PostMapping({"/callback"})
    public R callback(@RequestBody Map<String, Object> map) {
        String code = (String)map.get("code");
        if ("debug".equals(code)) {
            return R.error("测试模式不接收数据");
        } else {
            List<HashMap> data = (ArrayList)map.get("data");
            if (data == null) {
                throw new RuntimeException("数据为空");
            } else {
                EnvironmentData[] environmentData = MapToEnvironmentDataConverter.MapToEnvironmentData(data);
                this.service.saveBatch(Arrays.asList(environmentData));
                return R.ok();
            }
        }
    }

    public EnvironmentCallbackController(EnvironmentDataService service) {
        this.service = service;
    }
}
